home *** CD-ROM | disk | FTP | other *** search
- /*
- * Listing2: © Clemens Marschner 1994
- */
-
- #include "listing1.c"
-
- class Geburtsdatum : public Datum {
- char *Name;
- public:
- Geburtsdatum(char *, int,int,int);
- // Destruktoren wird eine Tilde vorangestellt.
- // Sie haben keine Argumente und sind typenlos:
- ~Geburtsdatum();
- char *GetName() { return Name; }; // inline
- void SetName(char*);
- void Print();
- };
-
- Geburtsdatum::Geburtsdatum
- (char *name, int t, int m, int j) : Datum(t,m,j)
- {
- // Konstruktor von »Datum« wird vorher aufrufen
- Name = new char[strlen(name)];
- // »new/delete« ersetzt malloc()/free() von C
- if(Name) // noch ohne »else«, das kommt noch
- { strcpy(Name, name); }
- }
-
- Geburtsdatum::~Geburtsdatum()
- { delete[] Name; // klappt auch, wenn Name == 0
- }
-
- void Geburtsdatum::Print()
- { cout << Name << ": ";
- Datum::Print(); // Aufrufen der überschriebenen Funktion
- }
-
- // ----- Und jetzt kommt das Hauptprogramm ----- //
- void main()
- {
- Geburtsdatum h("Heiner", 10, 3, 48);
- Geburtsdatum m("Maria", 22, 2, 53);
- h.Print(); cout << " heiratet ";
- m.Print(); cout << "\n";
- }
-